import pymysql
import pandas as pd

conn = pymysql.connect(host='localhost', user='root', password='123456', db='test', charset='utf8mb4')
df = pd.read_sql('SELECT * FROM test', conn=conn) \
    .pivot(index='id', columns='name', values='score') \
    .to_excel('./后勤部.xlsx', index=False)
conn.close()
# pivot进行数据透视
# df.to_excel('./后勤部.xlsx', index=False)
